package com.zjzywl.iotSendthings.util;

import org.springframework.http.ResponseEntity;

public class WebResult<D> {
	private int status = 200;//// 200.成功， 其它值，失败
	private String message=""; /// 消息
	private D data;
	public WebResult() {
		super();
	}
	public WebResult(D data) {
		this.data=data;
	}
	
	public WebResult(int status,String message) {
		this.data=data;
	}
	
	public WebResult(String message,int status) {
		this.status=status;
		this.message = message;
	}

	public WebResult(String message) {
		this.status=-100;
		this.message = message;
	}

	public static WebResult OK() {
		return new WebResult();
	}
	public static WebResult OK(Object obj) {
		return new WebResult(obj);
	}
	public static <T> WebResult OK(ResponseEntity<T> body){
		 if(body.getStatusCodeValue()==200){
			 return new WebResult(body.getBody());
		 }else{
			 return new WebResult(body.getStatusCodeValue(),"操作失败");
		 }
	}

	public static WebResult FAIL(String message) {
		return new WebResult(message);
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	public D getData() {
		return data;
	}
	public void setData(D data) {
		this.data = data;
	}
	
	
}
